import {Injectable} from 'angular2/core';
import {Jsonp, URLSearchParams} from 'angular2/http';
import {LanmonEvent} from './lanmonevent';
import {Observable}     from 'rxjs/Observable';

@Injectable()
export class WikipediaService {
  constructor(private jsonp: Jsonp) {}
  search (){
    let wikiUrl = 'http://localhost:8080/getEventinfo';
    var params = new URLSearchParams();
    //params.set('search', term); // the user's search value
    //params.set('action', 'opensearch');
    //params.set('format', 'json');
    //params.set('callback', 'JSONP_CALLBACK');
    // TODO: Add error handling
    return this.jsonp
      .get(wikiUrl, { search: params }).map(res=>{
        <LanmonEvent>res.json();
        alert(res.json());
      });
  }
}
